<?php
$baseUrl = $this->baseUrl();
?>
<?php 
/*
### Available validators:

* required
* validateMinLength
* validateMin
* validateMaxLength
* validateMax
* validateSameAs
* validateEmail
* validateUrl
* validateNumber
* validateInteger
* validateAlpha
* validateAlphaNum
* validatePhrase
* validatePhone
* validateDate
* validateCallback

 */

?>

<form action="javascript:submit();" autocomplete="off" class="uniForm" style="padding:0.5em 1em 1em 1.5em;">
        <h2>Agent Registration:</h2>
        <hr/>
        
        <fieldset id="basicID" >
        <h3>Basic:</h3>
        <div class="ctrlHolder">
          <label for=""><em>*</em>Registration ID:</label>
          <input name="app_no" id="app_no" value="AGNT-" size="35" maxlength="50" type="text" class="textInput required validatePhrase"/>
          <p class="formHint">Registration number for <span class="cName" >Agent</span>, e.g. AGNT-A-0020</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>Password</label>
          <input name="password" id="password" data-default-value="e.g. password" size="35" maxlength="15" type="text" class="textInput required validatePhrase"/>
          <p class="formHint">Password for <span class="cName" >Agent</span>. Max length 15 words</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>Sponsor's ID</label>
          <input name="sponsor_id" id="sponsor_id" value="AGNT-"  size="35" maxlength="50" type="text" class="textInput required validatePhrase"/>
          <p class="formHint">Sponser's registration id for <span class="cName" >Agent</span>, e.g. AGNT-A-0009</p>
        </div>
        
        </fieldset>
        <div id="formData">
         <fieldset>
        <h3>Personal:</h3>
        <div class="ctrlHolder noLabel">
          <ul class="alternate">
            <li><label for=""><em>*</em> First Name</label>
          <input name="first_name" id="first_name" data-default-value="e.g. Ravi" size="15" maxlength="50" type="text" class="textInput required validateAlpha"/></li>
            <li><label for=""> Middle Name</label>
          <input name="middle_name" id="middle_name" data-default-value="e.g. Kumar" size="15" maxlength="50" type="text" class="textInput"/></li>
            <li><label for=""> <em>*</em>Last Name</label>
          <input name="last_name" id="last_name" data-default-value="e.g. Gupta" size="15" maxlength="50" type="text" class="textInput required validateAlpha"/></li>
          </ul>
          <p class="formHint">Full Name of Agent</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>Father's Name</label>
          <input name="father_name" id="father_name" data-default-value="e.g. Sh. Mohan Lal" size="35" maxlength="50" type="text" class="textInput validatePhrase"/>
          <p class="formHint">Father's Name of <span class="cName" >Agent</span></p>
        </div>
        
        <div class="ctrlHolder">
          <label for="">Husband's Name(if applicable)</label>
          <input name="husband_name" id="husband_name" data-default-value="e.g. Sh. Brijesh Pal" size="35" maxlength="50" type="text" class="textInput"/>
          <p class="formHint">Husband's Name of <span class="cName" >Agent</span>(if applicable).</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>Mother's Name</label>
          <input name="mother_name" id="mother_name" data-default-value="e.g. Seeta Devi" size="35" maxlength="50" type="text" class="textInput validatePhrase"/>
          <p class="formHint">Mother's Name of <span class="cName" >Agent</span></p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>Date of Birth</label>
          <input name="dob" id="dob" data-default-value="e.g. 31-12-1990" readonly="readonly" size="35" maxlength="50" type="text" class="textInput required"/>
          <p class="formHint">Birthdate of <span class="cName" >Agent</span></p>
        </div>
        
        <div class="ctrlHolder">
          <p class="label">Gender</p>
          <ul class="blockLabels alternate">
            <li><label for=""><input name="gender" type="radio" value="M" title="Male"  checked="checked">Male</label></li>
            <li><label for=""><input  name="gender" type="radio" value="F" title="Female">Female</label></li>
          </ul>
          <p class="formHint">Gender</p>
        </div>
        
        <div class="ctrlHolder">
          <label for="">Nationality</label>
          <select id="nationality" name="nationality" class="selectInput">
          		<option value="IND" >INDIAN</option>
          		<option value="NRI" >NRI</option>
  		  </select>
          <p class="formHint">Nationality</p>
        </div>
        
        <div class="ctrlHolder">
          <label for="">Marital Status</label>
          <select id="marital_status" name="marital_status" class="selectInput">
          		<option value="S">Single</option>
          		<option value="M">Married</option>
          		<option value="D">Divorced</option>
          		<option value="SP">Separated</option>
          		</select>
          <p class="formHint">Marital Status of <span class="cName" >Agent</span></p>
        </div>
        
        
        <div class="ctrlHolder">
          <label for=""><em>*</em> PAN Number</label>
          <input name="pan" id="pan" data-default-value="e.g. 2GAF345Q" size="35" maxlength="50" type="text" class="textInput required validateAlphaNum"/>
          <p class="formHint"> PAN Number of <span class="cName" >Agent</span></p>
        </div>
        
        <div class="ctrlHolder">
          <label for="">Applicant Type:</label>
          <select id="applicant_type" name="applicant_type" class="selectInput">
          		<option value="IDVL">Individual</option>
          		<option value="CPNY">Company</option>
          		<option value="PROP">Proprietorship</option>
          		<option value="PART">Partnership</option>
          </select>
          <p class="formHint">Applicant Type</p>
        </div>
        
        <div id="aTypeSpec" style="display: none;" class="ctrlHolder">
          <label for="">Agent Type Specification(if applicable)</label>
          <input name="agent_type_spec" id="agent_type_spec" size="35" maxlength="50" type="text" class="textInput"/>
          <p class="formHint"> Agent Type Specification of <span class="cName" >Agent</span></p>
        </div>
        <div class="ctrlHolder">
          <label for=""><em>*</em> Occupation</label>
          <input name="occupation" id="occupation" data-default-value="e.g. Property Dealer" size="35" maxlength="50" type="text" class="textInput required"/>
          <p class="formHint">Occupation of <span class="cName" >Agent</span></p>
        </div>
         </fieldset> 
         <fieldset>
        <h3>Contact Information:</h3>
        <div class="ctrlHolder">
          <label for=""><em>*</em> Mobile Number</label>
          <input name="mobile_no" id="mobile_no" data-default-value="e.g. 9896102030" size="10" maxlength="50" type="text" class="textInput required validateInteger"/>
          <p class="formHint">Mobile Number of <span class="cName" >Agent</span>,just mention only personal 10 digit number(avoid +91 or 0 etc.)</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em> Alternate Number</label>
          <input name="alternate_no" id="alternate_no" data-default-value="e.g. 01712521521,9896767676" size="35" maxlength="50" type="text" class="textInput required"/>
          <p class="formHint">Alternate Numbers of <span class="cName" >Agent</span>,just mention landline number begining with 0</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>Email address</label>
          <input name="email" id="email" data-default-value="e.g. ravigupta@mail.com"  size="35" maxlength="50" type="text" class="textInput validateEmail required"/>
          <p class="formHint">A valid email address</p>
        </div>
      
        <div class="ctrlHolder">
          <label for=""><em>*</em>Email confirm</label>
          <input name="email_confirm" id="email_confirm" data-default-value="i.e. same as above"  size="35" maxlength="50" type="text" class="textInput validateSameAs email required"/>
          <p class="formHint"></p>
        </div>
        </fieldset>
        <fieldset>
        <h3>Permanent Address:</h3>
        <div class="ctrlHolder">
          <label for=""><em>*</em>Pin Code</label>
          <input name="ppostalcode" id="ppostcalcode"  data-default-value="e.g. 125001" size="35" maxlength="6" type="text" class="textInput required validateInteger"/>
          <p class="formHint">Pincode of communication address.</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>State/Province</label>
          <input name="pstate" id="pstate"  data-default-value="e.g. Haryana" size="35" maxlength="50" type="text" class="textInput required validateAlpha"/>
          <p class="formHint">State/Territory of communication address.</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>District</label>
          <input name="pdistrict" id="pdistrict" data-default-value="e.g. Mohindergarh" size="35" maxlength="50" type="text" class="textInput required validateAlpha"/>
          <p class="formHint">District of communication address.<br/>(It should be same as above if Union Territory)</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>City/Town/Village</label>
          <input name="pcity" id="pcity" data-default-value="e.g. Narnaul" size="35" maxlength="50" type="text" class="textInput required validateAlpha"/>
          <p class="formHint">City/Town/Village of communication address.<br/>(It may be same as District)</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>Address</label>
          <textarea name="padd" id="padd" data-default-value="e.g. H.no. 3, PWD B&R Colony, Near Old court"  class="validatePhrase"  rows="25" cols="25"></textarea>
          <p class="formHint">House number and Area etc.</p>
        </div>
        </fieldset>

        <div class="ctrlHolder noLabel">
        </div>
                
        <div class="ctrlHolder noLabel">
          <ul>
            <li><label for=""><input name="is_cp_same" id="is_cp_same" value="false" type="checkbox"/> Communication and Permanent Addesses are same.</label></li>
          </ul>
          <p class="formHint">Click if both addresses are same.</p>
        </div>

        <fieldset  id="c_fset">
        <h3>Correspondance Address:</h3>
        <div class="ctrlHolder">
          <label for=""><em>*</em>Pin Code</label>
          <input name="cpostalcode" id="cpostalcode" data-default-value="e.g. 160027" size="35" maxlength="6" type="text" class="textInput required validateInteger"/>
          <p class="formHint">Pincode of permanent address.</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>State/Territory</label>
          <input name="cstate" id="cstate" data-default-value="e.g. Chandigarh" size="35" maxlength="50" type="text" class="textInput required validateAlpha"/>
          <p class="formHint">State/Territory of permanent address.</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>District</label>
          <input name="cdistrict" id="cdistrict"  data-default-value="e.g. Chandigarh" size="35" maxlength="50" type="text" class="textInput required validateAlpha"/>
          <p class="formHint">District of permanent address.<br/>(It should be same as above if Union Territory)</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>City/Town/Village</label>
          <input name="ccity" id="ccity" data-default-value="e.g. Chandigarh" size="35" maxlength="50" type="text" class="textInput required validateAlpha"/>
          <p class="formHint">City/Town/Village of permanent address.<br/>(It may be same as District)</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>Address</label>
          <textarea name="cadd" id="cadd"  data-default-value="e.g. H.no. 2135, Sector 9C"   class="validatePhrase"  rows="25" cols="25"></textarea>
          <p class="formHint">House number and Area etc.</p>
        </div>
        </fieldset>

        
        <fieldset>
        <h3>Nominee:</h3>
        <div class="ctrlHolder">
          <label for="">Nominee's name</label>
          <input name="nominee_name" id="nominee_name" data-default-value="e.g. Suraj Kumar" size="35" maxlength="50" type="text" class="textInput validatePhrase"/>
          <p class="formHint">Nominee's name</p>
        </div>
        
        <div class="ctrlHolder">
          <label for="">Relation with Nominee</label>
          <input name="nominee_relation" id="nominee_relation" data-default-value="e.g. Father" size="35" maxlength="50" type="text" class="textInput validatePhrase"/>
          <p class="formHint"><span class="cName" >Agent</span>'s relationship with nominee.</p>
        </div>
        
        <div class="ctrlHolder">
          <label for="">Nominee PAN</label>
          <input name="nominee_pan" id="nominee_pan" data-default-value="e.g. AIPR78979D2" size="35" maxlength="50" type="text" class="textInput validatePhrase"/>
          <p class="formHint">Nominee's PAN.</p>
        </div>
        
        <div class="ctrlHolder noLabel">
        </div>
                
        <div class="ctrlHolder noLabel">
          <ul>
            <li><label for=""><input name="is_np_same" id="is_np_same" value="false" type="checkbox"/> Permanent Addesses of both agent and nominee is same.</label></li>
          </ul>
          <p class="formHint">Click if both addresses are same.</p>
        </div>
        
        </fieldset>
        
        <fieldset id="n_fset">
        <h3>Nominee Permanent Address:</h3>
        <div class="ctrlHolder">
          <label for=""><em>*</em>Pin Code</label>
          <input name="npostalcode" id="npostalcode" data-default-value="e.g. 160027" size="35" maxlength="6" type="text" class="textInput required validateInteger"/>
          <p class="formHint">Pincode of permanent address.</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>State/Territory</label>
          <input name="nstate" id="nstate" data-default-value="e.g. Chandigarh" size="35" maxlength="50" type="text" class="textInput required validateAlpha"/>
          <p class="formHint">State/Territory of permanent address.</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>District</label>
          <input name="ndistrict" id="ndistrict"  data-default-value="e.g. Chandigarh" size="35" maxlength="50" type="text" class="textInput required validateAlpha"/>
          <p class="formHint">District of permanent address.<br/>(It should be same as above if Union Territory)</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>City/Town/Village</label>
          <input name="ncity" id="ncity" data-default-value="e.g. Chandigarh" size="35" maxlength="50" type="text" class="textInput required validateAlpha"/>
          <p class="formHint">City/Town/Village of permanent address.<br/>(It may be same as District)</p>
        </div>
        
        <div class="ctrlHolder">
          <label for=""><em>*</em>Address</label>
          <textarea name="nadd" id="nadd"  data-default-value="e.g. H.no. 2135, Sector 9C"   class="validatePhrase"  rows="25" cols="25"></textarea>
          <p class="formHint">House number and Area etc.</p>
        </div>
        
        </fieldset>
        
        
      <div class="buttonHolder">
        <button type="reset" class="secondaryAction">Clear form</button>
        <button type="submit" class="primaryAction">Submit</button>
      </div>
      
 <div id="submitStatus" style="display:none;" class="ui-state-highlight ui-corner-all" ></div>
 </div>
 </form>
    <script>
	var urlAgentRegister = "<?php echo $this->url(array('controller' => 'agent', 'action' => 'imod'))?>";
	var urlCanSponser = "<?php echo $this->url(array('controller' => 'agent', 'action' => 'cansponser'))?>";

      $(function(){
        $('form.uniForm').uniform({
          prevent_submit : true
        });

        //serverDateObj = $.datepicker.parseDate('dd-mm-yy', $('#datetext').text());
        $("#dob").datepicker({
        	dateFormat: 'dd-mm-yy',
        	changeMonth: true,
			changeYear: true,
			yearRange: '-60:-17',
			onClose : function(dateText, inst) {
				this.focus();
				}
        });
        
        $('#first_name').change(function(){
            var cName = this.value;
        	$('.cName').text(cName);
        });


        $("#is_cp_same").click(function(){
            if ($(this).is(':checked')) {
            	$(this).val(true);
            	$('#c_fset :input').remove();
            	$('#c_fset').hide('slow');
			} else {
				$(this).val(false);
				location.reload();
			}
            
		});


        $("#is_np_same").click(function(){
            if ($(this).is(':checked')) {
            	$(this).val(true);
            	$('#n_fset :input').remove();
            	$('#n_fset').hide('slow');
			} else {
				$(this).val(false);
				location.reload();
			}
            
		});

        $("#applicant_type").change(function(){
            if ('IDVL' != $(this).val()) {
            	$('#aTypeSpec').show('slow');
			} else {
            	$('#aTypeSpec').hide('slow');
			}
            
		});


        $('#sponsor_id').change(function(){
            var sid = this.value;
            $.ajax({
                url : urlCanSponser,
                data : {"agent_id":sid},
                success: function(jStatus){
                    if (jStatus) {
                    	$('#formData').show('slow');
                    	$('#errorBox').text('').parent().hide();
                    	$('#first_name').focus();
					}
                },
                    error: function(response) {
                    	$('#errorBox').text(response.responseText).parent().show();
						$('#formData').hide('slow');
                        console.log(response);
                        }
                    });
        });
        
      });

      function submit() {  
          $.ajax({
              url : urlAgentRegister,
              data : getValues(),
              success: function(jStatus){
                  $( "#submitStatus" ).text(jStatus).toggle( 'blind', '', 'slow', function(){  
                  	setTimeout(function(){
                      	//window.location.reload();
                      	},1400);
                  } );
              },
                  error: function(response) {
                	  $('#errorBox').text(response.responseText).parent().show();
                      console.log(response);
                      }
                  });
      }

      function getValues() {
          var formData = {oper:'add'}; 
          $('form.uniForm :input')
          		.not('button,:input[value^="e.g."]')
          		.each(function(){ 
          			formData[this.name] = this.value; 
              });
          var gender = $('input:radio[name=gender]:checked').val();
          formData.gender = gender; 
		return formData;
	}
      </script>
      
<?php
$this->headScript()->appendFile($baseUrl.'/plugins/uni-form/js/uni-form-validation.jquery.js');
$this->headLink()->prependStylesheet($baseUrl.'/plugins/uni-form/css/uni-form.css');
$this->headLink()->prependStylesheet($baseUrl.'/plugins/uni-form/css/smooth.uni-form.css');
$this->headLink()->prependStylesheet($baseUrl.'/plugins/uni-form/demos/css/demo.css');
?>